<template>
    <!-- 总容器 -->
    <div class="wrapper">
        <header>
            <i class="fa fa-angle-left" onclick="history.go(-1)"></i>
            <p>选择体检套餐</p>
            <div></div>
        </header>
        <div class="top-ban"></div>


        <ul class="setmeal">
            <li v-for="(setmeal, index) in setmealArr" :key="setmeal.smId">
                <!-- <li v-for="(item, index) in state.setmeals" :key="index"> -->
                <div class="item">
                    <div class="item-left" onclick="location.href='selectdate.html'">
                        <h3 @click="toConfirmorder(item)">{{ setmeal.type === 1 ? '男士套餐' : '女士套餐' }}</h3>
                        <p>{{ setmeal.name }}</p>
                    </div>
                    <div class="item-right" @click=" isShowEvent(index)">
                        <p>详情</p>
                        <i class="fa fa-angle-down"></i>
                    </div>
                </div>
                <div class=" item-content" v-if="setmeal.isShow">
                    <table>
                        <tr>
                            <th>检查项目</th>
                            <th>检查内容</th>
                            <th>检查意义</th>
                        </tr>
                        <!-- in setmeal.sdList -->
                        <tr v-for="detail in setmeal.sdList" :key="detail.sdId">
                            <td>{{ detail.checkItem.ciName }}</td>
                            <td>{{ detail.checkItem.ciContent }}</td>
                            <td>{{ detail.checkItem.meaning }}</td>
                        </tr>

                    </table>
                </div>
            </li>

        </ul>

        <div class="bottom-ban"></div>


        <Footer></Footer>
    </div>

</template>

<script>
import axios from "axios";
import { useRouter } from "vue-router";
import { ref, reactive, onMounted } from "vue";
import qs from 'qs';
import Footer from "../components/Footer.vue";
import { getSessionStorage } from "../common.js"
import { set } from "core-js/core/dict";

export default {
    //setup 是 Vue 3 Composition API 的入口函数，所有组件逻辑都在这里实现
    setup() {
        //存储套餐详情
        // const setmealDetail = ref(null);
        //是否显示
        // const isDetial = ref(false);
        const isDetial = reactive({});

        const router = useRouter();
        const state = reactive({
            //  setmeals: [],
            // setmeal: {},
            setmealArr: []
        });

        //点击时展开
        // const toGet = (smId) => {
        //     // alert('111');
        //     // console.log("1111");
        //     console.log("222");
        //     isDetial[smId] = !isDetial[smId];
        //     if (isDetial[smId] && !state.setmeal[smId]) {
        //         fetchSetmealById(smId);
        //     }
        // };
        function isShowEvent(index) {
            state.setmealArr[index].isShow = !state.setmealArr[index].isShow;
        }
        const toConfirmorder = (setmeal) => {
            router.push({
                path: '/confirmorder',
                // query: { name: setmeal.name }
                query: {
                    setmeal: JSON.stringify(setmeal),
                }
            });
        };
        const fetchSetmealById = (smId) => {
            // const params = { id: smId };
            const params = { smId };
            axios.post('SetmealController/getSetmealById', qs.stringify(params))
                .then((response) => {
                    console.log("111");
                    // 3. 处理响应结果
                    // alert(id);
                    // console.log('后端返回数据：', response.data);
                    state.setmeal[smId] = response.data;
                    // let setmeals = response.data; // 后端返回的setmeal列表

                })
                .catch((error) => {
                    // 捕获请求异常（如网络错误）
                    console.error(error);
                });
        }

        const fetchSetmeals = () => {
            axios.post('SetmealController/listSetmealByType', qs.stringify({ type: getSessionStorage('users').sex }))
                .then((response) => {
                    //arr就是变量
                    let arr = response.data;
                    conslose.log(response.data);
                    for (let i = 0; i < arr.lenth; i++) {
                        //isShow控制详情是显示还是隐藏
                        arr[i].isShow = false;
                    }
                    state.setmealArr = arr;




                    // 3. 处理响应结果
                    console.log('后端返回数据：', response.data);
                    state.setmeals = response.data;
                    // let setmeals = response.data; // 后端返回的setmeal列表

                })
                .catch((error) => {
                    // 捕获请求异常（如网络错误）
                    console.error(error);
                });
        }


        onMounted(() => {
            fetchSetmeals();
        });
        return {
            //  isDetial,
            //toGet,
            isShowEvent,
            toConfirmorder,
            //toHospital,
            state
        }






    },

}

</script>

<style scoped>
/*********************** 总容器 ***********************/
.wrapper {
    width: 100%;
    height: 100%;
    background-color: #F9F9F9;
}

/*********************** header ***********************/
header {
    width: 100%;
    height: 15.7vw;
    background-color: #FFF;

    position: fixed;
    left: 0;
    top: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    box-sizing: border-box;
    padding: 0 3.6vw;
}

header .fa {
    font-size: 8vw;
}

/*********************** footer ***********************/
footer {
    width: 100%;
    height: 14.2vw;
    box-sizing: border-box;
    border-top: solid 1px #E9E9E9;
    background-color: #FFF;

    position: fixed;
    left: 0;
    bottom: 0;
}

footer ul {
    width: 100%;
    height: 14.2vw;
    display: flex;
    align-items: center;
    justify-content: space-around;
}

footer ul li {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    font-size: 3vw;
    color: #999;

    user-select: none;
    cursor: pointer;
}

footer ul li .fa {
    font-size: 5vw;
}

/*********************** common样式 ***********************/
.top-ban {
    width: 100%;
    height: 15.7vw;
}

.bottom-ban {
    width: 100%;
    height: 14.2vw;
}

/*********************** setmeal ***********************/
.setmeal {
    width: 100%;
    margin-top: 10vw;
}

.setmeal li {
    width: 92.8vw;
    margin: 0 auto;
    border: solid 1px #EEE;
    border-radius: 1vw;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, .08);
    background-color: #FFF;
    margin-bottom: 3.6vw;
}

.setmeal li .item {
    width: 100%;
    height: 20vw;
    color: #555;

    display: flex;
    align-items: center;
}

.setmeal li .item .item-left {
    flex: 0 0 72vw;
    height: 20vw;
    border-right: solid 1px #EEE;
    box-sizing: border-box;
    padding-left: 12vw;

    display: flex;
    flex-direction: column;
    justify-content: center;

    user-select: none;
    cursor: pointer;
}

.setmeal li .item .item-left h3 {
    font-size: 4.3vw;
    font-weight: 600;
}

.setmeal li .item .item-left p {
    font-size: 4vw;
    margin-top: 1vw;
}

.setmeal li .item .item-right {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;

    user-select: none;
    cursor: pointer;
}

.setmeal li .item .item-right p {
    font-size: 4vw;
    margin-right: 2vw;
}

.setmeal li .item-content {
    /*display: none;*/
    width: 100%;
    background-color: #FFF;
}

.setmeal li .item-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 4vw;
    color: #555;
}

.setmeal li .item-content table tr {
    display: flex;
}

.setmeal li .item-content table tr td,
.setmeal li .item-content table tr th {
    flex: 1;
}

.setmeal li .item-content table tr th {
    text-align: center;
    background-color: #EEE;
    height: 10vw;
    line-height: 10vw;
}

.setmeal li .item-content table tr td {
    border: solid 1px #EFEFEF;
    box-sizing: border-box;
    padding: 2vw;
}
</style>